public class test3 {
    //力扣 978.最长湍流子数组
    public int maxTurbulenceSize(int[] arr) {
        //创建dp数组
        //初始化
        //填表
        //返回值
        int n = arr.length;
        int[] f = new int[n];
        int[] g = new int[n];
        f[0] = 1;g[0] = 1;
        int maxf = 1 ,maxg = 1;
        for(int i = 1;i<n;i++){
            int a = arr[i-1], b = arr[i];
            if(a<b){
                f[i] = g[i-1]+1;
                g[i] = 1;
            }else if(a>b){
                f[i] = 1;
                g[i] = f[i-1]+1;
            }else{
                f[i] = 1;g[i] = 1;
            }
            maxf = Math.max(f[i], maxf);
            maxg = Math.max(g[i], maxg);
        }
        return Math.max(maxf,maxg);
    }
}
